//
//  NegotiationHistoryController.m
//  ZSYH
//
//  Created by 主事丫环HU on 2020/6/12.
//  Copyright © 2020 魏堰青. All rights reserved.
//

#import "NegotiationHistoryController.h"
#import "WorkerHistoryCell.h"
#import "MerchantHistoryCell.h"
#import "NegotiationHistoryModel.h"
@interface NegotiationHistoryController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation NegotiationHistoryController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self requestHistoryData];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)setupUI{
    self.title = @"协商历史";
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    self.view.backgroundColor = Main_BackGroundColor;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [[UIView alloc] init];
}
- (void)requestHistoryData{
    self.dataArray = [NSMutableArray arrayWithCapacity:0];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"id"] = self.orderID;
    [MBProgressHUD showHUDAddedTo:self.view msg:@"加载中..." animated:YES];
    [NetWorkTool POST:getDetailsListById param:param success:^(id dic) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        // 状态
        self.dataArray = [NegotiationHistoryModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];
        if (self.dataArray.count > 0) {
            NegotiationHistoryModel * model = [self.dataArray lastObject];
            model.isLast = YES;
        }
        [self.tableView reloadData];
    } other:^(id dic) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    } fail:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    } needUser:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NegotiationHistoryModel *model = self.dataArray[indexPath.row];
    // 0师傅发起审核 1开始回寄 3确认回寄
    if ([model.state isEqualToString:@"0"] || [model.state isEqualToString:@"3"] || [model.state isEqualToString:@"4"]) {
        return 70;
    } else {
        return 90;
    }
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NegotiationHistoryModel *model = self.dataArray[indexPath.row];
    // 如果状态是0 1 3 用师傅的cell
    if ([model.state isEqualToString:@"0"] || [model.state isEqualToString:@"3"] || [model.state isEqualToString:@"4"]) {
        WorkerHistoryCell *cell = [WorkerHistoryCell cellWithTableView:tableView];
        cell.model = model;
        return cell;
    } else {
        MerchantHistoryCell *cell = [MerchantHistoryCell cellWithTableView:tableView];
        cell.model = model;
        return cell;
    }
    
    
}

@end
